var Amqp = require('../amqp');
/**
 *
 * @class
 * @extends handlers.Abstract
 * @exports Channel as handlers.Channel
 * @param connection
 */
function Channel(/**handlers.Connection*/connection){
    this.connection = connection;
}
require('sys').inherits(Channel, require('events').EventEmitter);
Object.defineProperty(Channel.prototype, 'channelId', {
    get: function(){
        return this._channelId;
    },
    set: function(/**Number*/channelId){
        if ('_channelId' in this) {
            if (this._channelId == channelId) return;
            connection.removeAllListeners('Amqp.Channel[' + this._channelId + ']');
        }
        this._channelId = channelId;
        var channel = this;
        connection.addListener('Amqp.Channel[' + channelId + ']', function(frame){
            var classId = frame.method.classId, methodId = frame.method.methodId;
            channel.emit('Amqp.' + Amqp.Class[classId] + '.' + Amqp.Class[classId][methodId], frame);
        });
    }
});
/**
 * Add channel id for amqp frame.
 *
 * @see handlers.Abstract#processFrame
 * @param frame
 */
Channel.prototype.processFrame = function(/**Object*/frame){
    frame.channel = this.channelId;
    this.connection.processFrame(frame);
};
exports.Channel = Channel;
